package coumo.jdbc.jci;

import java.net.Socket;
import java.net.InetAddress;
import java.util.Vector;
import java.util.ArrayList;
import java.io.*;
import javax.transaction.xa.Xid;
import coumo.jdbc.driver.COUMODriver;
import coumo.jdbc.driver.COUMOException;

public class UConnection
{

  /*
   * the normal constructor of the class UConnection
   */

  UConnection(String ip, int port, String dbname, String user, String passwd, String url)
      throws COUMOException
  {
  }


  public void setCharset(String newCharsetName)
      throws java.io.UnsupportedEncodingException
  {
  }

  public String getCharset()
  {
    return "";
  }

  synchronized public void close()
  {
  }

  synchronized public void endTransaction(boolean type)
  {
  }

  synchronized public OutputStream getOutputStream()
  {
    return null;
  }

  synchronized public String getDatabaseProductVersion()
  {
    return null;
  }

  synchronized public int getIsolationLevel()
  {
    return 0;
  }

  synchronized public String getQueryplanOnly(String sql)
  {
    return "";
  }

  synchronized public UStatement getSchemaInfo(int type, String className,
      String attributePattern, byte flag)
  {
    return null;
  }
      

  public boolean isClosed()
  {
    return false;
  }

  synchronized public UStatement prepare(String sqlStatement, byte prepareFlag)
  {
    return (prepare(sqlStatement, prepareFlag, false));
  }

  synchronized public UStatement prepare(String sqlStatement, byte prepareFlag,
      boolean recompile_flag)
  {
    return null;
  }

  synchronized public void setIsolationLevel(int level)
  {
  }

  public boolean getAutoCommit()
  {
  return false;
  }

  public int currentIsolationLevel()
  {
  return 0;
  }

  void cancel() throws  IOException
  {
  }

  // jci 3.0
  private void disconnect()
  {
  }

  private void clearTransactionList()
  {
  }
  // end jci 3.0

  public boolean isServerSideJdbc()
  {
  return false;
  }

  public void turnOnAutoCommitBySelf()
  {
  }

  public void turnOffAutoCommitBySelf()
  {
  }

  static void ping(String ip, int port, int socketTimeout) throws IOException
  {
    Socket clientSocket = null;
    DataOutputStream outputStream = null;
    DataInputStream  inputStream = null;

    try
    {
      String ping_msg = "PING_TEST!";

      clientSocket = new Socket(InetAddress.getByName(ip), port);
      clientSocket.setTcpNoDelay(true);
      clientSocket.setSoTimeout(socketTimeout);

      outputStream = new DataOutputStream(clientSocket.getOutputStream());

      outputStream.write(ping_msg.getBytes());
      outputStream.flush();		      

      inputStream = new DataInputStream(clientSocket.getInputStream());		    		    
      inputStream.readInt();

    }
    catch(Exception e)
    {
      throw new IOException(e.getMessage());
    }
    finally
    {
      if (outputStream != null)
      {
        outputStream.close();
      }
      if (inputStream != null)
      {
        inputStream.close();
      }
      if (clientSocket != null)
      {	    	
        clientSocket.close();
      }
    }  
  }

}
